<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>

          <a-col :span="24">
            <a-form-model-item label="用户押金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountDeposit">
              <span>{{ model.accountDeposit }}</span>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountId">

              <a-input-number v-model="model.amountMoney" placeholder="退款金额,不填为全额退款" :precision="2" :min="0" :max="99999999.99" style="width: 100%"></a-input-number>
            </a-form-model-item>
          </a-col>




          <a-col :span="24">

            <a-col :span="24">
              <a-form-model-item label="审核备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reviewComment">
                <a-input v-model="model.reviewComment" placeholder="请输入审核备注"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">

            </a-col>
             <a-button type="primary" @click="searchQuery" >审核通过</a-button>
             <a-button type="primary" @click="searchReset" style="margin-left: 8px">审核不通过</a-button>
            <a-col :span="4">

            </a-col>
          </a-col>

        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction, postAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'RevertCarReviewForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          withdrawalStatus:[{ required: true, message: '请选择提现状态!' }],
        },
        url: {
          add: "/rental/revertCarReview/add",
          edit: "/rental/revertCarReview/review",
          queryById: "/rental/revertCarReview/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      searchQuery(){
        this.model.revertStatus=2
        this.submitForm()
      },
      searchReset(){
        this.model.revertStatus=3
        this.submitForm()
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            httpurl+=this.url.edit;
            method = 'post';
            let data={
              id: this.model.id,
              reviewComment: this.model.reviewComment,
              revertStatus: this.model.revertStatus,
              amountMoney:this.model.amountMoney
            }
            postAction(httpurl,data).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>